package com.jbp.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.dao.ApiLogDao;
import com.jbp.model.ApiLog;
import com.jbp.utils.IPReqUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
public class ApiLogService extends ServiceImpl<ApiLogDao, ApiLog> implements IService<ApiLog> {

    @Autowired
    private HttpServletRequest request;

    public void save(String path, String params) {
        ApiLog apiLog = new ApiLog();
        apiLog.setPath(path);
        apiLog.setParams(params);
        apiLog.setIp(IPReqUtil.getIpAddr(request));
        apiLog.setCreateTime(new Date());
        apiLog.setPort(IPReqUtil.getRemotePort(request));
        save(apiLog);
    }
}